package com.pansoft.kline.widget;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.efounder.chat.view.CommonOtherPopWindow;
import com.pansoft.kline.util.SelfSelectUtils;
import com.pansoft.openplanet.R;

/**
 * @author : zzj
 * @e-mail : zhangzhijun@pansoft.com
 * @date : 2018/12/3 17:00
 * @desc :
 * @version: 1.0
 */
public class KlinePopWindowManager {

    /**
     * 自选  和 分享弹窗
     *
     * @param context   context
     * @param imageView 图标
     */
    public static void showOptionalAndSharePop(final Context context, View imageView, final
    String marketId, final OnMenuSelectedListener onMenuSelectedListener) {

        final CommonOtherPopWindow commonOtherPopWindow = new CommonOtherPopWindow((Activity) context);
        final long id = SelfSelectUtils.getIsSelectedId(marketId);
        if (id != -1) {
            //删除自选
            commonOtherPopWindow.addMenuButton(context.getString(R.string.kline_detail_pop_delete_optional), R.drawable.ic_kline_delete_optional, true)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (onMenuSelectedListener != null) {
                                onMenuSelectedListener.onDeleteSelect(id);
                            }
                            commonOtherPopWindow.dismiss();
                        }
                    });
        } else {
            //加入自选
            commonOtherPopWindow.addMenuButton(context.getString(R.string.kline_detail_pop_add_optional), R.drawable.ic_kline_add_optional, true)
                    .setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (onMenuSelectedListener != null) {
                                onMenuSelectedListener.onAddSelect();
                            }
                            commonOtherPopWindow.dismiss();
                        }
                    });
        }
        commonOtherPopWindow.addMenuButton(context.getString(R.string.kline_detail_pop_share), R.drawable.ic_kline_share)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (onMenuSelectedListener != null) {
                            onMenuSelectedListener.onShare();
                        }
                        commonOtherPopWindow.dismiss();
                    }
                });

        commonOtherPopWindow.showPopupWindow(imageView);
    }

    public interface OnMenuSelectedListener{
        /** 分享截图 **/
        void onShare();

        /** 加入、删除自选 **/
        void onAddSelect();

        void onDeleteSelect(long id);
    }

}
